<link href="//cdn.bootcss.com/weui/1.1.2/style/weui.min.css" rel="stylesheet">
<script src="//cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<div style="padding-bottom:50px;" id='app'>
    <div class="page__bd">
        <div class="weui-panel weui-panel_access">
            <div class="weui-panel__hd"><?=$user['realname']?>的<?=C('XIAJI_NAME')?>列表</div>
            <div class="weui-panel__bd">
                <template v-for="(item,index) in list">
                    <a 
                        class="weui-cell weui-cell_access" >
                        <div  class="weui-cell__hd">
                            <img style="width:60px;margin-right:5px;display:block" :src="item.headimgurl" alt="" onerror="javascript:this.src='__STATIC__admin/images/error.png';" >
                        </div>
                        <div 
                            class="weui-cell__bd weui-cell_primary">
                            <h4 class="weui-media-box__title">{{item.realname?item.realname:item.nickname}}</h4>
                            <p class="weui-media-box__desc"> 等级：{{item.grade_name}} <br> 手机：{{item.mobile}}</p>
                        </div>
                        <span style="position: absolute;right:25px;" >
<!--                            <span 
                                @click="goToZs(item)"
                                class="weui-btn weui-btn_mini weui-btn_default">查看证书</span>-->
                        </span>
                    </a>
                </template>
            </div>
            <div 
                v-if="!empty"
                class="weui-panel__ft">
                <a  
                    @click="getMore()"
                    class="weui-cell weui-cell_access weui-cell_link">
                    <div class="weui-cell__bd">查看更多</div>
                    <span class="weui-cell__ft"></span>
                </a>    
            </div>
            
            <div v-if="edituser!=''" class="page dialog js_show">
                <div id="dialogs">
                    <div class="js_dialog" id="androidDialog1" v-show="isdialog">
                        <div class="weui-mask"></div>
                        <div class="weui-dialog weui-skin_android">
                            <div class="weui-dialog__hd">
                                <strong class="weui-dialog__title">修改等级</strong>
                            </div>
                            <div class="weui-dialog__bd">
                                <div style="color:#000;" class="weui-cells weui-cells_form">
<!--                                    <div class="weui-cell">
                                        <div class="weui-cell__hd"><label class="weui-label">等级</label></div>
                                        <div class="weui-cell__bd">
                                            <input v-model="edituser.grade" class="weui-input" type="number" placeholder="请输入等级">
                                        </div>
                                    </div>-->
                                    <div class="weui-cell">
                                        <div class="weui-cell__bd">
                                            <p>当前用户:{{edituser.nickname}}</p>
                                        </div>
                                        <div class="weui-cell__ft"></div>
                                    </div>
                                    <div class="weui-cell weui-cell_select weui-cell_select-after">
                                        <div class="weui-cell__hd">
                                            <label for="" class="weui-label">等级</label>
                                        </div>
                                        <div class="weui-cell__bd">
                                            <select v-model="edituser.grade_id" class="weui-select">
                                                <?php foreach($gradelist as $k=>$v){ ?>
                                                <option value="<?=$v['grade_id']?>"><?=$v['grade_name']?></option>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="weui-dialog__ft">
                                <a @click="isdialog=false" class="weui-dialog__btn weui-dialog__btn_default">取消</a>
                                <a @click="saveChange" class="weui-dialog__btn weui-dialog__btn_primary">保存</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
</div>
<include file="Common:nav" />
<script>
    var app = new Vue({
        el: '#app',
        data: {
            empty: true,
            list: [],
            page: 1,
            edituser:{},
            editindex:0,
            isdialog:false
        },
        created: function () {
            this.getMore();
        },
        methods: {
            getMore: function () {
                var self = this;
                $.ajax({
                    type: 'get',
                    url: '/mobile/user/daili?uid=<?=get("uid")?>&p=' + self.page,
                    success: function (res) {
                        layer.closeAll();
                        self.page++;
                        if(!res) {
                            self.empty = true;
                            return false;
                        }
                        if(res.length>0) {
                            for(var i=0;i<res.length;i++) {
                                self.list.push(res[i]);
                            }
                            self.empty = false;
                        }
                        if(res.length<10) {
                            self.empty = true;
                        }
                    },
                    beforeSend:function () {
                        layer.open({
                            type: 2,
                            content: '加载中'
                        })
                    }
                })
            },
            goToZs:function (item) {
                location.href="/mobile/zhengshu?uid="+item.uid;
            },
            goToXiaji:function(item){
                if(item.floor>=3) {
                    return false;
                }
                location.href="/mobile/user/daili?uid="+item.uid;
            },
            changeGrade:function(index){
                this.edituser = $.extend({},this.list[index]);
                this.editindex = index;
                this.isdialog = true;
            },
            saveChange:function(){
                var self = this;
                $.ajax({
                    type:'post',
                    url:'/mobile/user/changegrade',
                    data:{
                        grade_id:self.edituser.grade_id,
                        uid:self.edituser.uid
                    }
                }).then(function(res){
                    if(res.ret==0){
                        layer.open({
                            content:res.msg,
                            time:2
                        });
                        self.list.splice(self.editindex,self.edituser);
                        location.reload();
                        self.editindex = 0;
                        self.edituser = {};
                        this.isdialog = false;
                    }else{
                        layer.open({
                            content:res.msg,
                            time:2
                        });
                    }
                })
            }
        }
    })
</script>